package NC;

public class NC5 {

    public static void main(String[] args) {
        TreeNode listNode1 = new TreeNode(1);
        TreeNode listNode2 = new TreeNode(2);
        TreeNode listNode3 = new TreeNode(3);
        TreeNode listNode4 = new TreeNode(4);
        TreeNode listNode5 = new TreeNode(5);
        listNode1.left= listNode2;
        listNode2.left = listNode3;
        listNode1.right = listNode4;
        listNode2.right = listNode5;
        sumNumbers(listNode1);

    }

    public static int sumNumbers (TreeNode root) {
        return(dsp(root,0));
    }

    public static int dsp(TreeNode root, int sum) {
        if (root == null) return 0;
        sum=sum*10+root.val;
        if(root.left==null&&root.right==null) return sum;
        return dsp(root.left,sum)+dsp(root.right,sum);
    }
}
